package cc.autoapi.pucong.auto.flow.core.flow.execNode.selfenum;

import cc.autoapi.pucong.auto.flow.core.flow.execNode.task.system.*;

import org.apache.commons.lang3.StringUtils;

/**
 * 节点类型
 *
 * @author pucong
 */
public enum NodeTypeEnum {

    API_CONFIG("apiConfig", ApiConfigTask.class),
    CRON_CONFIG("cronConfig", CronConfigTask.class),
    SWITCH("switch", SwitchTask.class),
    IF("if", IfTask.class),
    FOR("for", ForTask.class),
    JAVA_SCRIPT("javaScript", JavaScriptTask.class),
    JS_SCRIPT("jsScript", JsScriptTask.class),
    PYTHON_SCRIPT("pythonScript", PythonScriptTask.class),
    PROCESS("process", ProcessTask.class);

    private String key;
    private Class taskClass;

    NodeTypeEnum(String key, Class taskClass) {
        this.key = key;
        this.taskClass = taskClass;
    }

    public String getKey() {
        return key;
    }

    public Class getTaskClass() {
        return taskClass;
    }

    public static NodeTypeEnum getItemByValue(String value) {
        NodeTypeEnum[] itemArr = NodeTypeEnum.values();
        if (StringUtils.isNotBlank(value)) {
            for (NodeTypeEnum item : itemArr) {
                if (value.equals(item.key)) {
                    return item;
                }
            }
        }
        return null;
    }
}
